package com.compass.doctor.ui.mine.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.compass.doctor.R
import com.compass.doctor.callback.OnCustomButtonClick
import com.compass.doctor.databinding.LayoutHospitalizedRecordItemBinding
import com.compass.doctor.databinding.LayoutTestAndInspectionItemBinding
import com.compass.doctor.ui.chat.attachment.ExamineAttachment
import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseRecyclerViewAdapter
import com.compass.framework.ext.gone
import com.compass.framework.ext.onClick
import com.compass.framework.ext.visible
import com.compass.framework.glide.setUrlCircle
import com.compass.framework.manager.DictionariesManager
import com.compass.framework.model.InspectionRecord
import com.compass.framework.model.Message
import com.compass.framework.utils.BigDecimalUtils
import com.compass.framework.utils.DateUtils
import com.compass.framework.utils.getDrawableResource

/**
 * Description： 检验检查adapter
 * Date:2023/12/21 21:18
 */
class TestAndInspectionAdapter : BaseRecyclerViewAdapter<InspectionRecord, LayoutTestAndInspectionItemBinding>() {

    private lateinit var onCustomButtonClick: OnCustomButtonClick
    fun setBottomCallBack(onChatBottomClick: OnCustomButtonClick) {
        this.onCustomButtonClick = onChatBottomClick
    }

    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<LayoutTestAndInspectionItemBinding>,
        item: InspectionRecord?,
        position: Int
    ) {
        if (item == null) return
        holder.binding.apply {
            tvInspectionName.text = item.inspectionName
            tvPrice.text = "￥${BigDecimalUtils.divide(item.price)}"
            tvTime.text = "开具时间：${DateUtils.conversionTime(item.createTime,DateUtils.FORMAT_TWO)}"
            tvStatus.text = DictionariesManager.getOrderInspectionSourceString(item.status.toString())
            ivHead.setUrlCircle(item.patientAvatar)
            tvName.text = item.patientName
            ivSex.background =
                if (item.patientSex == 1) getDrawableResource(R.mipmap.icon_male) else getDrawableResource(
                    R.mipmap.icon_female
                )
            tvAge.text = item.patientAge

            if (item.status == 0) {
                tvCancel.visible()
            } else {
                tvCancel.gone()
            }
            tvCancel.onClick {

                onCustomButtonClick.onButtonCallBack(position,"cancel")
            }
        }
    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): LayoutTestAndInspectionItemBinding {
        return LayoutTestAndInspectionItemBinding.inflate(layoutInflater, parent, false)
    }
}